package com.ruoyi.match.service.impl;

import java.util.List;

import com.ruoyi.match.mapper.NoticeConfirmMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.match.mapper.NoticeMapper;
import com.ruoyi.match.domain.Notice;
import com.ruoyi.match.service.INoticeService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 查看所有公告Service业务层处理
 * 
 * @author zhangrui
 * @date 2025-04-04
 */
@Service
public class NoticeServiceImpl implements INoticeService 
{
    @Autowired
    private NoticeMapper noticeMapper;


    @Autowired
    private NoticeConfirmMapper noticeConfirmMapper;

    /**
     * 查询查看所有公告
     * 
     * @param noticeId 查看所有公告主键
     * @return 查看所有公告
     */
    @Override
    public Notice selectNoticeByNoticeId(Long noticeId)
    {
        return noticeMapper.selectNoticeByNoticeId(noticeId);
    }

    /**
     * 查询查看所有公告列表
     * 
     * @param notice 查看所有公告
     * @return 查看所有公告
     */
    @Override
    public List<Notice> selectNoticeList(Notice notice)
    {
        return noticeMapper.selectNoticeList(notice);
    }


    /**
     * 查询某个队伍所有公告列表
     *
     * @param teamId 查看某个队伍的所有公告
     * @return 查看所有公告集合
     */
    @Override
    public List<Notice> selectNoticeList(Long teamId) {
//        把teamId赋值到notice
        Notice notice = new Notice();
        notice.setTeamId(teamId);
        //执行查询
        return noticeMapper.selectNoticeList(notice);
    }

    /**
     * 新增查看所有公告
     * 
     * @param notice 查看所有公告
     * @return 结果
     */
    @Override
    public int insertNotice(Notice notice)
    {
        return noticeMapper.insertNotice(notice);
    }



    /**
     * 修改查看所有公告
     * 
     * @param notice 查看所有公告
     * @return 结果
     */
    @Override
    public int updateNotice(Notice notice)
    {
        return noticeMapper.updateNotice(notice);
    }

    /**
     * 批量删除查看所有公告
     * 
     * @param noticeIds 需要删除的查看所有公告主键
     * @return 结果
     */
    @Override
    public int deleteNoticeByNoticeIds(Long[] noticeIds)
    {
        return noticeMapper.deleteNoticeByNoticeIds(noticeIds);
    }

    /**
     * 删除查看所有公告信息
     * 
     * @param noticeId 查看所有公告主键
     * @return 结果
     */
    @Override
    public int deleteNoticeByNoticeId(Long noticeId)
    {
        return noticeMapper.deleteNoticeByNoticeId(noticeId);
    }

    @Override
    @Transactional
    public int deleteNoticeByTeamId(Long teamId) {
        //删除某个队伍的所有公告
        noticeMapper.deleteNoticeByTeamId(teamId);

        //删除某个队伍的所有公告的确认记录
        List<Long> noticeIds = noticeMapper.selectNoticeIdByTeamId(teamId);
        System.out.println(noticeIds);
        if (noticeIds.size() != 0){
            noticeConfirmMapper.deleteNoticeConfirmByNoticeIds2(noticeIds);
        }

        return 1;
    }
}
